using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;


namespace Anno.GateWay
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>()
                    .UseAnnoSvc();
                    webBuilder.UseKestrel(opts =>
                    {
                        // bind directly to a socket handle or unix socket
                        // opts.listenhandle(123554);
                        // opts.listenunixsocket("/tmp/kestrel-test.sock");

                        //opts.Listen(System.Net.IPAddress.Loopback, port: Const.AppSettings.GetAppSettings<int>("ListenPort", "5000"));
                        //opts.ListenAnyIP(Const.AppSettings.GetAppSettings<int>("ListenPort", "5000"));
                        //opts.ListenLocalhost(5004, opts => opts.UseHttps());
                        //opts.ListenLocalhost(5005, opts => opts.UseHttps());

                        if(Const.AppSettings.GetAppSettings<bool>("UseHttps", "false"))
                        {
                            opts.ListenLocalhost(Const.AppSettings.GetAppSettings<int>("ListenPort", "5001"), opts => opts.UseHttps());
                        }
                        else
                        {
                            opts.ListenAnyIP(Const.AppSettings.GetAppSettings<int>("ListenPort", "5000"));
                        }
                    });
                });
    }
}
